// maincontrol.cpp : contains the class for the window that accepts files
// to open them in their appropriate editor windows
//$Id: MainControl.cpp 35 2009-08-29 17:19:44Z brwarner2 $
#include "StdAfx.h"
#include "MainControl.h"
#include "SpriteWindow.h"
#include "AreaEditor.h"

CMainControl::CMainControl(void)
{
}

CMainControl::~CMainControl(void)
{
}

void CMainControl::RegisterClasses() {}

LRESULT CMainControl::Message(UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case WM_CREATE:
		{
			DragAcceptFiles(m_hWindow, TRUE);
		}break;
	case WM_DROPFILES:
		{
			//Get drop information
			HDROP hdrop = (HDROP)(wParam);

			//Get filename
			UINT size = DragQueryFile(hdrop, 0, 0, 0);
			char *buffer = new char[size+1];
			DragQueryFile(hdrop, 0, buffer, size+1);

			boost::filesystem::path path = buffer;
			if( boost::filesystem::extension(path) == ".png" )
			{
				CSpriteWindow* pWindow = GetFactory<CSpriteWindow>()->Create(50, 50);
				pWindow->LoadImageFile(buffer);
			}
			else if( boost::filesystem::extension(path) == ".lvl" )
			{
				CAreaEditor* pWindow = GetFactory<CAreaEditor>()->Create(200, 200);
				pWindow->LoadArea( buffer );
			}
		}break;
	case WM_DESTROY:
		{
			PostQuitMessage(0);
		}break;
	}
	return DefWindowProc( m_hWindow, msg, wParam, lParam );
}

void CMainControl::WindowInfo(::WindowInfo &info)
{
	info.width = 200;
	info.height = 200;
	info.classname = "CMainControl";
	info.windowName = "Editor Suite Control Panel";
}